package com.xsf.jieyou.message.consumer;

import com.xsf.jieyou.cloud.api.CloudMongoDbUserLogService;
import com.xsf.jieyou.cloud.domain.UserLog;
import com.xsf.jieyou.commons.utils.MapperUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.stereotype.Service;

/**
 * 消息消费者
 *
 * @author xsf
 * @version v1.0.0
 * @date 2019/11/16 0016 0:29
 * @see com.xsf.jieyou.message.consumer
 **/
@Service
public class TbUserLogReceive {
    @Reference(version = "1.0.0")
    private CloudMongoDbUserLogService cloudMongoDbUserLogService;

    /**
     * 向MongoDB中新增日志记录。
     *
     * @param jsonUserLog {@link String} JSON格式的日志对象
     */
    @StreamListener(value = "user-log-topic")
    public void receiveAdminLoginLog(String jsonUserLog) throws Exception {
        UserLog userLog = MapperUtils.json2pojo(jsonUserLog, UserLog.class);
        this.cloudMongoDbUserLogService.insert(userLog);
    }
}
